﻿
using IDEAMS.core;
using IDEAMS.model.setting;
using IDEAMS.utils;
using log4net;
using System.Drawing;
using System.IO;

namespace IDEAMS.model.etalon
{
    public class PrintStatus
    {
        private static ILog logger = LogManager.GetLogger(typeof(PrintStatus));

        public bool preEtalon;
        public bool postEtalon;

        public PrintStatus()
        {
           Reset();
        }

        public PrintStatus(PrintStatus status) : this()
        {
            Copy(status);
        }

        public void Reset()
        {
            preEtalon = true;
            postEtalon = true;
        }

        public void Copy(PrintStatus status)
        {
            this.preEtalon = status.preEtalon;
            this.postEtalon = status.postEtalon;
        }

        public PrintStatus Clone()
        {
            return new PrintStatus(this);
        }

        public int Load(string serialNo)
        {
            int rn = 0;

            string dataFile = string.Format(TW_App.fileManager.printStatusFile, serialNo);
            bool existsFlag = File.Exists(dataFile);
            if (!existsFlag)
            {
                Reset();
                logger.WarnFormat("报告是否显示文件[{0}]不存在", dataFile);
                return -2;
            }

            PrintStatus printStatus = XmlUtil.Load<PrintStatus>(dataFile);
            if (printStatus != null)
            {
                //todo:设置变量
                Copy(printStatus);
                rn = 0;
            }
            else
            {
                Reset();
                logger.ErrorFormat("加载报告是否显示文件[{0}]失败", dataFile);
                rn = -3;
            }

            return rn;
        }

        public bool Save(string serialNo)
        {
            string dataFile = string.Format(TW_App.fileManager.printStatusFile, serialNo);

            PrintStatus printStatus = new PrintStatus(this);
            bool rn = XmlUtil.Save<PrintStatus>(dataFile, printStatus);
            return rn;
        }
    }
}
